/*
    XTU OJ: 1328
    by: fifth_light
*/

#include <stdio.h>

int sum_list[15];

int calc_once(int number, int radix) {
    int sum = 0;
    int now = number;
    while (now > 0) {
        int digit = now % radix;
        sum += digit;
        now /= radix;
    }
    return sum;
}

void calc_sum(int number) {
    for(int i = 2; i <= 16; i++) {
        sum_list[i - 2] = calc_once(number, i);
    }
}

typedef struct {
    int sum;
    int cnt;
} sum_item;

int main(void) {
    int t;
    scanf("%d", &t);
    for(int i = 0; i < t; i++) {
        int num;
        scanf("%d", &num);
        calc_sum(num);
        int sums_count = 0;
        sum_item sums[16];
        for (int i = 0; i < 15; i++) {
            int n = sum_list[i];
            int has_sum = 0;
            for (int j = 0; j < sums_count; j++) {
                if (sums[j].sum == n) {
                    sums[j].cnt++;
                    has_sum = 1;
                    break;
                }
            }
            if (!has_sum) {
                sums[sums_count].sum = n;
                sums[sums_count].cnt = 1;
                sums_count++;
            }
        }
        for (int i = 0; i < sums_count; i++) {
            for (int j = 0; j < sums_count - 1; j++) {
                if (sums[j].sum > sums[j + 1].sum) {
                    sum_item tmp = sums[j + 1];
                    sums[j + 1] = sums[j];
                    sums[j] = tmp;
                }
            }
        }
        int max_cnt = 0;
        for (int i = 0; i < sums_count; i++) {
            if (sums[i].cnt > max_cnt) {
                max_cnt = sums[i].cnt;
            }
        }
        printf("%d\n", max_cnt);
        for (int i = 0; i < sums_count; i++) {
            if (sums[i].cnt == max_cnt) {
                printf("%d", sums[i].sum);
                for (int j = 0; j < 15; j++) {
                    if (sum_list[j] == sums[i].sum) {
                        printf(" %d", j + 2);
                    }
                }
                putchar('\n');
            }
        }
    }
    return 0;
}
